package com.terrace.db.system.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.terrace.db.constant.DBType;
import com.terrace.db.system.dao.OrganizationDao;
import com.terrace.db.system.dao.UserOrganizationDao;
import com.terrace.db.system.mapper.entity.Organization;
import com.terrace.db.system.mapper.entity.UserOrganization;
import com.terrace.db.system.service.OrganizationService;
import com.terrace.core.mybatis.entity.Pagination;
import com.terrace.core.mybatis.plugin.pagination.PaginationHelper;
import com.terrace.core.spring.datasource.annotation.DataSource;

@Service
@Transactional
@DataSource(name = DBType.ADMIN)
public class OrganizationServiceImpl implements OrganizationService {
	
	@Autowired
	private OrganizationDao organizationDao;
	
	@Autowired
	private UserOrganizationDao userOrganizationDao;

	@Override
	public int saveOrganizationSelective(Organization org) {
		return organizationDao.saveOrganizationSelective(org);
	}
	
	@Override
	public int saveUserOrganization(UserOrganization userOrganization) {
		return userOrganizationDao.saveUserOrganization(userOrganization);
	}

	@Override
	public int deleteUserOrganizationById(String userId, String orgId) {
		return userOrganizationDao.deleteUserOrganizationById(userId, orgId);
	}

	@Override
	public int deleteOrganizationById(String orgId) {
		return organizationDao.deleteOrganizationById(orgId);
	}

	@Override
	public int updateOrganizationByIdSelective(Organization org) {
		return organizationDao.updateOrganizationByIdSelective(org);
	}

	@Override
	public Organization selectOrganizationById(String orgId) {
		return organizationDao.selectOrganizationById(orgId);
	}
	
	@Override
	public List<Organization> selectOrganizationsByUserId(String userId) {
		return organizationDao.selectOrganizationsByUserId(userId);
	}
	
	@Override
	public Pagination<Organization> selectOrganizationForPagination(Pagination<Organization> pagination, Organization org) {
		PaginationHelper.prepare(pagination);
		return PaginationHelper.execute(organizationDao.selectOrganizationForPagination(org));
	}

}
